package com.zjj.lbw.guava.splitter;


import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * @author zhanglei.zjj
 * @description guava字符串处理之Joiner
 * @date 2023/7/16 15:33
 */
public class TestGuavaStringJoiner {
    @Test
    public void testString() {
        String str = "hell,world,123,,test";
        String[] split = str.split(",");
        for (String s : split) {
            System.out.println("s:" + s);
        }
    }

    @Test
    public void joinerListTest() {
        List<String> list = Lists.newArrayList("wowo", "kkk", null, "wowoowowwow");
        //String joinStr = Joiner.on(",").skipNulls().join(list);
        String joinStr = Joiner.on(",").useForNull("----").join(list);
        System.out.println(joinStr);
    }

    @Test
    public void withMapTest() {
        Map<Integer, String> maps = Maps.newHashMap();
        maps.put(1, "哈哈");
        maps.put(2, "压压");

        String joinStr = Joiner.on(",").withKeyValueSeparator(":").join(maps);

        System.out.println(joinStr);

    }
}
